<?php

	if (!isset($_GET['q']) || empty ($_GET['q'])) die();

	require_once 'googleOptions.php';
	require_once 'googleSearch.php';
	require_once 'searchParser.php';
	require_once 'searchPager.php';


//Example

	$q			=	preg_replace('#%#','',$_GET['q']);
	$start	=	(isset($_GET['start'])) ? (int)$_GET['start'] : 0;

	$search	=	new googleSearch();							//An instance of our search proxy
	$search->setQuery($_GET['q']);							//Search term, usually, something like user input

	$search->setStart( (isset($_GET['start'])&&(int)$_GET['start']>0) ? (int)$_GET['start'] : 1);	//Paging, start start (see the startr class)

	$search	=	$search->doGoogleSearch();					//Do the search!

	try { 

		$template	=	new searchParser($search,'resources/templates/');	//Parse the search, 
		$template	=	$template->getSmartyObject();		//Get the Smarty Object!;

		$pager		=	new searchPager ($search);			//Create a new pager instance, we have to assign it to our template! else we wont be able to do the paging
		$pager->setPage("results.php?start=%s&q=$q");	//Set the base URL so the pager can actually now where does it has to page, %s gets replaced with the page number
		$pager->setCurrentPage($start);						//This is the current page, a simple offset 

		$template->assign('pager',$pager->display());	//Assign the pager to the template in order to show it
		echo $template->fetch ('search.tpl');				//Display The contents

	} catch (Exception $e) {

		var_dump( $e->getMessage());							//dump the error, if any

	}

?>
